package com.budwk.app.util.poiUtils.fireHiddenOffice;

import com.budwk.app.sqfw.dto.FireHiddenCheckWordDTO;
import com.budwk.app.sqfw.dto.FireHiddenOfficeWordDTO;
import com.budwk.app.sqfw.enums.StreetEnum;
import com.budwk.app.sqfw.vo.GenerateWordAndPdfUrlVO;
import com.budwk.app.util.poiUtils.fireHiddenOffice.impl.WeiQingMenFireHiddenOffice;
import com.budwk.app.util.poiUtils.fireHiddenOffice.impl.YuHongFireHiddenOffice;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ywm
 * @project wk-mini
 * @description 消防安全工厂
 * @date 2023/11/29 14:34:18
 */
public class FireHiddenOfficeFactory {

    private static final Map<String, IFireHiddenOffice> MAP = new HashMap<>();
    static {
        MAP.put(StreetEnum.WEI_QING_MEN_STREET.getName(), new WeiQingMenFireHiddenOffice());
        MAP.put(StreetEnum.YUN_TAN_STREET.getName(), new YuHongFireHiddenOffice());
    }

    /**
     * 生成pdf
     * @param wordDTO
     * @return
     */
    public static GenerateWordAndPdfUrlVO createOffice(FireHiddenCheckWordDTO wordDTO) {
        IFireHiddenOffice fireHiddenOffice = getIFireHiddenOffice(wordDTO.getUnitName());
        if (fireHiddenOffice == null) return null;
        return fireHiddenOffice.createOffice(wordDTO);
    }

    /**
     * 生成拆分pdf
     * @param wordDTO
     */
    public static void createSplitPdf(FireHiddenOfficeWordDTO wordDTO) {
        IFireHiddenOffice fireHiddenOffice = getIFireHiddenOffice(wordDTO.getUnitName());
        if (fireHiddenOffice == null) return;
        fireHiddenOffice.createSplitPdf(wordDTO);
    }

    public static String createWordTemplate(FireHiddenOfficeWordDTO wordDTO) {
        IFireHiddenOffice fireHiddenOffice = getIFireHiddenOffice(wordDTO.getUnitName());
        if (fireHiddenOffice == null) return null;
        return fireHiddenOffice.createWordTemplate(wordDTO);
    }

    private static IFireHiddenOffice getIFireHiddenOffice(String unitName) {
        for (String key : MAP.keySet()) {
            if (unitName.contains(key)) {
                return MAP.get(key);
            }
        }
        return null;
    }
}
